/*
 * Created on 2021年11月29日
 * 
 * Copyright(c) YuZhou Big Data Laboratory CO.,Ltd, 2022.  All rights reserved.
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/
package org.pentaho.di.ui.spoon.cluster;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.yzbdl.lanius.core.quartz.entity.TaskCronInfo;

/**
 * 创建这个类,主要是对List集合中的数据记录进行筛选和转化.
 * 是"内容器"的作用.
 * 内容器中主要是对setInput()输入的数据集集合(本例子中指的是在PeopleFactory中封装好的List集合)做处理.
 * 并且转换化成一个数组返回.
 * 
 * 实现对应的接口IStructuredContentProvider,然后实现其中的方法.
 * 
 * @author yzbdl@yzbdl.ac.cn
 * @version 1.0
 * @since 1.0
 */
public class TableViewerContentProvider implements IStructuredContentProvider {

    @Override
    public void dispose() {
        
    }

    @Override
    public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        
    }
    
    /**
     * 实现IStructuredContentProvider接口之后,主要复写的就是这个getElements()方法.
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
    public Object[] getElements(Object inputElement) {//setInput传过来的是一个集合
        if(inputElement instanceof List){//对这个参数进行类型的判断.
        	ArrayList list = (ArrayList<TaskCronInfo>)inputElement;
        	Object[] aa = list.toArray();
        	CopyOnWriteArrayList<TaskCronInfo> cal = new CopyOnWriteArrayList(aa);
        	for (Iterator iterator = cal.iterator(); iterator.hasNext();) {
        		TaskCronInfo taskCronInfo = (TaskCronInfo) iterator.next();
				if ("delete".equals(taskCronInfo.getType())) {
					cal.remove(taskCronInfo);
				}
			}
            return cal.toArray();//将setInput传过来的List变成一个数组输出
        }else{
            return new Object[0];
        }
    }
}